{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>{{ user.name }}的个人档案</h2>
            {% if current_user.id == user.id %}
            <a href="{{ url_for('users.edit_profile') }}" class="btn btn-primary">编辑档案</a>
            {% endif %}
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card mb-4">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">基本信息</h5>
            </div>
            <div class="card-body">
                <p><strong>用户名:</strong> {{ user.username }}</p>
                <p><strong>姓名:</strong> {{ user.name }}</p>
                <p><strong>角色:</strong> {{ '管理员' if user.role == 'admin' else '成员' }}</p>
                <p><strong>加入时间:</strong> {{ user.created_at.strftime('%Y-%m-%d') }}</p>
            </div>
        </div>
        
        {% if user.articles.count() > 0 %}
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">发布的文章</h5>
            </div>
            <div class="card-body">
                <div class="list-group">
                    {% for article in user.articles %}
                    <a href="{{ url_for('articles.view', id=article.id) }}" class="list-group-item list-group-item-action">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1">{{ article.title }}</h5>
                            <small>{{ article.created_at.strftime('%Y-%m-%d') }}</small>
                        </div>
                        <small>
                            {% for skill in article.skills %}
                            <span class="badge bg-secondary">{{ skill.name }}</span>
                            {% endfor %}
                        </small>
                    </a>
                    {% endfor %}
                </div>
            </div>
        </div>
        {% endif %}
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">技能</h5>
            </div>
            <div class="card-body">
                {% if user.skills %}
                <div class="d-flex flex-wrap gap-2 mb-3">
                    {% for skill in user.skills %}
                    <span class="badge bg-secondary">{{ skill.name }}</span>
                    {% endfor %}
                </div>
                {% else %}
                <p class="text-muted">暂无技能标签</p>
                {% endif %}
                
                {% if current_user.id == user.id %}
                <a href="{{ url_for('users.edit_profile') }}" class="btn btn-outline-primary">编辑我的技能</a>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}